/*
 * MyGWT User Extensions
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.mygwt.ux.samples.explorer.client;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import net.mygwt.ui.client.event.BaseEvent;
import net.mygwt.ui.client.event.SelectionListener;
import net.mygwt.ui.client.widget.Button;
import net.mygwt.ui.client.widget.ButtonBar;
import net.mygwt.ui.client.widget.WidgetContainer;
import net.mygwt.ui.client.widget.layout.FlowLayout;
import net.mygwt.ux.client.widgets.wizard.Wizard;
import net.mygwt.ux.client.widgets.wizard.WizardDialog;
import net.mygwt.ux.client.widgets.wizard.WizardPage;

/**
 * 
 * @author Chris Worley
 *
 */
public class SimpleWizardPage extends Page {
  protected void createWidget(WidgetContainer container) {

    final Wizard simpleWizard = new Wizard() {

      /*
       * (non-Javadoc)
       * 
       * @see net.mygwt.ui.client.wizard.Wizard#canFinish()
       */
      public boolean canFinish() {
        return super.canFinish();
      }

      /*
       * (non-Javadoc)
       * 
       * @see net.mygwt.ui.client.wizard.Wizard#getNextPage()
       */
      protected WizardPage getNextPage() {
        // TODO Auto-generated method stub
        return super.getNextPage();
      }

      /*
       * (non-Javadoc)
       * 
       * @see net.mygwt.ui.client.wizard.Wizard#getPreviousPage()
       */
      protected WizardPage getPreviousPage() {
        // TODO Auto-generated method stub
        return super.getPreviousPage();
      }

    };

    // first page
    simpleWizard.addPage(new WizardPage("my-mbox-info", "Simple Wizard",
        "Example of a wizard.  This is the first page in the wizard.") {
      protected Widget createPageComponent() {
        return createPagePanel("Wizard Page 1");
      }
    });

    // second page
    simpleWizard.addPage(new WizardPage("my-mbox-warning", "Simple Wizard",
        "This is the second page in the wizard.") {
      protected Widget createPageComponent() {
        return createPagePanel("Wizard Page 2");
      }
    });

    ButtonBar buttons = new ButtonBar();
    buttons.add(new Button("Wizard", new SelectionListener() {
      public void widgetSelected(BaseEvent be) {
        // show wizard
        new WizardDialog(simpleWizard).open();
      }
    }));

    container.setLayout(new FlowLayout(10));
    container.add(buttons);
  }

  /**
   * create generic page panel for simple wizard
   * 
   * @param string
   * @return
   */
  private Widget createPagePanel(String string) {
    VerticalPanel panel = new VerticalPanel();
    panel.setWidth("100%");
    Label label = new Label(string);
    panel.add(label);
    panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_CENTER);
    panel.setCellVerticalAlignment(label, HasVerticalAlignment.ALIGN_MIDDLE);
    return panel;
  }

}
